{% extends "base.html" %}
{% block title %}Categorias{% endblock %}
{% block head %}
    {{ super() }}
 
	<script type="text/javascript" src="/assets/js/jquery.js"></script>
  	<script type="text/javascript" src="/assets/js/jquery.validate.js"></script>

 	<script>
		$(document).ready(function() {   
			$("#form1").validate({   
				onkeyup: false,
				rules: {name: {required: true
							{% if not category.is_saved() %}
							  ,remote: {type:"post",
							   	        url:"validate"
							   	       }
						    {% endif %}				              }   
					   },   
				messages: {name: {required: "Este campo es obligatorio"
							{% if not category.is_saved() %}
				                  ,
				                  remote: "El nombre ya existe"
				            {% endif %}
				                  }
				          }   
				}
			);   
		}); 
  </script>
    
{% endblock %}
{% block content %}
	<h1>Administracion de Categorias</h1>
	<br>
	<form id ="form1" action="/category/edit" method="post">
	<input type="hidden" name="id_category" value="{% if category.is_saved() %} {{category.key().id()}} {% else %} -1 {% endif %}" />
    	<table>
      		<tr>
				<td><label>Nombre*</label></td>
      			<td><input type="text" style="width: 300px" name="name" value={% if category.name ==None %} "" {%else%} "{{category.name}}" {%endif%} /></td>
      		</tr>
      		<tr>
      			<td><label>Tipo</label></td>
      			<td>
					<select name="type" style="width: 100px">
					  <option {% if category.type =="fijo" %} selected="selected" {% endif %} value="fijo">Fijo</option>
					  <option {% if category.type =="variable" %} selected="selected" {% endif %} value="variable">Variable</option>
					</select>
				</td>
      		</tr>
      	</table>
      	<br>
        <table>
        	<tr>
        		<td><input name="btnSave" type="submit" value="Guardar" /> </td>
        		<td><input class="cancel" name="btnCancel" type="submit" value="Volver" /></td>
        		<td>{% if category.is_saved() %}
        		       <input class="cancel" name="btnDelete" type="submit" value="Eliminar" />
        		    {% endif %}
        		</td>        
        	</tr>
        </table>
    </form>
    <br>
{% endblock %}
